
/*
 * =====================================================================================
 *
 *       Filename:  disk_shm.h
 *
 *    Description:  Share memory operation by semaphore
 *
 *        Version:  1.0
 *        Created:  10/24/2011
 *       Revision:  none
 *       Compiler:  gcc
 *
 *
 * =====================================================================================
 */
#ifndef  DISK_SHM_INC
#define  DISK_SHM_INC

/**
 *  Macro Definition
 */
#ifdef __cplusplus
extern "C"
{
#endif

#define MAX_SYSTEM_CMD_NUM      32
#define SYSTEM_TIME_OUT         (10*60*100)	//10ms in unit

#define SUCCESS 0
#define FAILURE -1


/**
 *  Data Struction Definition
 */

/* system command execute status */
	enum system_status_t
	{
		SYSTEM_EMPTY,			/* system command not ready */
		SYSTEM_READY,			/* system command ready */
		SYSTEM_EXECUTING,		/* system is executing */
		SYSTEM_FINISHED			/* system executed OK or time out */
	};

	struct system_shminfo_t
	{
		int avail;				/* systemd index available */
		int ret;				/* systemd return value */
		int timeout;			/* systemd executing command timeout */
		enum system_status_t status;	/* status of system command */
		char cmd[100];			/* command string */
	};

	struct system_shareinfo_t
	{
		struct system_shminfo_t *shm;	/* share memory handle */
		int shmid;				/* share memory flag id */
		int semid;				/* semaphore flag id */
	};


/**
 *  \brief 
 *  \param  
 *  \return 
 */
	int system_init (struct system_shareinfo_t *shareinfo);

/**
 *  \brief 
 *  \param  
 *  \return 
 */
	int system_sem_in (struct system_shareinfo_t *shareinfo);

/**
 *  \brief 
 *  \param  
 *  \return 
 */
	int system_sem_out (struct system_shareinfo_t shareinfo);

#ifdef __cplusplus
};
#endif

#endif							/* ----- #ifndef DISK_SHM_INC  ----- */
